<template>
	<view>

		<view class="" style="display: flex;justify-content: center;">
			<image src="../../../static/erweima.jpg" style="width: 500rpx;height: 500rpx;" show-menu-by-longpress="true" mode=""></image>
		</view>
		
		<view class="info_item" style="color: #40A0F2;border-bottom: 0;">
			识别二维码绑定公众号后,可收到以下提醒
		</view>
		
		<view class="info_item">
			<text class="head_text ">绑定微信</text>
			<switch style="transform: scale(0.7);margin-left: 50rpx;" :checked="checkd_is_bing" @change="changeBing" />
		</view>
		<view class="info_item">
			<text class="head_text ">待办提醒</text>
			<switch style="transform: scale(0.7);margin-left: 50rpx;" :checked="checkd_is_done" @change="changeDone" />
		</view>
		<view class="info_item">
			<text class="head_text ">待阅提醒</text>
			<switch style="transform: scale(0.7);margin-left: 50rpx;" :checked="checkd_is_result"
				@change="changeResult" />
		</view>
		<!-- <view class="info_item">
			<text class="head_text ">考勤提醒</text>
			<switch style="transform: scale(0.7);margin-left: 50rpx;" :checked="checkd_is_ckock"
				@change="changeCkock" />
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token: '',
				member_id: '',
				company_id: '',

				checkd_is_bing: true,
				checkd_is_done: true,
				checkd_is_result: true,
				checkd_is_ckock: true,
				
				value_bing:'',
				value_done:'',
				value_result:'',
				value_ckock:'',
				
				
				wxcode: ''
			}
		},
		onLoad() {
			this.token = uni.getStorageSync('btlh_process_token') || ''
			this.member_id = uni.getStorageSync('btlh_process_member_id') || ''
			this.company_id = uni.getStorageSync('bthl_process_LoginCompanyId') || ''
			
			this.departmentChange();
			// #ifdef MP-WEIXIN
			wx.login({
				success: (res) => {
					this.wxcode = res.code
				}
			})
			// #endif
		},
		methods: {
			/* is_bing绑定微信
				is_done待办提醒
				is_result待阅提醒
				is_clock考勤提醒 */
			// 绑定微信
			async changeBing(e) {
				console.log(e.detail.value)
				e.detail.value==true?this.value_bing = '1':this.value_bing = '0';
				const wxres = await this.$myRequest({
					url: 'WeiXin/bing_set',
					data: {
						member_id: this.member_id,
						token: this.token,
						code: this.wxcode,
						set_type:'is_bing',
						value:this.value_bing
					}
				})
				if(wxres.data.code == 200){
					uni.showToast({
						title:'设置成功',
						icon:'none'
					})
				}
			},
			async changeDone(e) {
				console.log(e.detail.value)
				e.detail.value==true?this.value_done= '1':this.value_done = '0';
				const wxres = await this.$myRequest({
					url: 'WeiXin/bing_set',
					data: {
						member_id: this.member_id,
						token: this.token,
						code: this.wxcode,
						set_type:'is_done',
						value:this.value_done
					}
				})
				if(wxres.data.code == 200){
					uni.showToast({
						title:'设置成功',
						icon:'none'
					})
				}
				
			},
			async changeResult(e) {
				console.log(e.detail.value)
				e.detail.value==true?this.value_result= '1':this.value_result = '0';
				const wxres = await this.$myRequest({
					url: 'WeiXin/bing_set',
					data: {
						member_id: this.member_id,
						token: this.token,
						code: this.wxcode,
						set_type:'is_result',
						value:this.value_result
					}
				})
				
				if(wxres.data.code == 200){
					uni.showToast({
						title:'设置成功',
						icon:'none'
					})
				}
				
			},
			async changeCkock(e) {
				console.log(e.detail.value)
				e.detail.value==true?this.value_ckock= '1':this.value_ckock = '0';
				const wxres = await this.$myRequest({
					url: 'WeiXin/bing_set',
					data: {
						member_id: this.member_id,
						token: this.token,
						code: this.wxcode,
						set_type:'is_clock',
						value:this.value_ckock
					}
				})
				
				if(wxres.data.code == 200){
					uni.showToast({
						title:'设置成功',
						icon:'none'
					})
				}
				
			},

			// 是否打开1是，0否；
			async departmentChange() {
				const res =await this.$myRequest({
					url:'WeiXin/bing_get',
					data:{
						member_id: this.member_id,
						token: this.token,
					}
				});
				console.log(res)
				if(res.data.datas.is_bing == 0 || res.data.datas.is_bing =='0'){
					this.checkd_is_bing = false
				}
				if(res.data.datas.is_clock == 0 || res.data.datas.is_clock =='0'){
					this.checkd_is_ckock = false
				}
				if(res.data.datas.is_result == 0 || res.data.datas.is_result=='0'){
					this.checkd_is_result = false
				}
				if(res.data.datas.is_done == 0 || res.data.datas.is_done =='0'){
					this.checkd_is_done = false
				}

			},


		}
	}
</script>

<style lang="scss">
	.info_item {
		width: 690rpx;
		height: auto;
		border-bottom: 1rpx solid #E3E3E3;
		margin-left: 30rpx;
		margin-top: 44rpx;
		display: flex;
		justify-content: space-around;
	}

	.head_text {

		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
	}
</style>
